home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0124_Scroll Bars.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  5KB  |  155 lines

  1. USES dos, crt;
  2.  
  3. CONST
  4.     v_vidseg   : WORD = $B800;  { $B000 for mono }
  5.     v_columns  : BYTE = 80;     { Number of CRT columns }
  6.  
  7. VAR
  8.     x : BYTE;
  9. {
  10. the dspat routine, as you can see.  Displays a string QUICKLY
  11. If 'Col' (=columns, NOT color) is negative (-1) the centence will be centered.
  12. Works also in exotic screenmodes, like 132x44, 100x44 or whatever you like.
  13. }
  14. procedure dspat(Str : string; Col : integer; Row,Attr : byte); assembler;
  15. asm
  16.   push ds          { Save Turbo's DS }
  17.   mov es,v_vidseg  { Place VideoBuffer in es }
  18.   xor dh,dh        { Clear DH }
  19.   mov dl,v_columns { Bytes per row }
  20.  
  21.   lds si,Str       { DS:SI pts to Str }
  22.   xor cx,cx        { clear CX }
  23.   mov cl,[si]      { String len counted in CX }
  24.   jcxz @l5         { If null, quit }
  25.   inc si           { Point DS:SI to first char }
  26.  
  27.   mov ax,Col       { Get Column value }
  28.   cmp ax,0
  29.   jge @l6          { Absolute, or centered? }
  30.  
  31.   mov ax,dx
  32.   sub ax,cx        { Substract stringlen from total }
  33.   shr ax,1         { Centre}
  34.  
  35.  @l6:
  36.   mov di,ax
  37.   shl di,1         { Double for attributes }
  38.  
  39.   mov al,Row       { Get Row value }
  40.   mul dl           { Times rows }
  41.   shl ax,1
  42.  
  43.   add di,ax        { ES:DI pts to lst pos }
  44.   cld              { Direction flag forward }
  45.   mov ah,Attr      { Get Attribute }
  46.  @l1:
  47.   lodsb            { Get a character}
  48.   stosw            { Write it with attribute }
  49.   loop @l1         { Go do next }
  50.  @l5:
  51.   pop ds           { Restore DS and quit }
  52. end;
  53.  
  54. procedure filltext(Dir : char; X1,Y1,X2,Y2,Col : byte); assembler;
  55. asm
  56.   push ds          { Save Turbo's DS }
  57.  
  58.   xor dh,dh        { Clear DH }
  59.   mov dl,v_columns { Bytes per row (number of columns) }
  60.  
  61.   xor ah,ah
  62.   mov es,v_vidseg  { Place VideoBuffer in ES and DS }
  63.   mov al,[X1]
  64.   mov di,ax
  65.   shl di,1         { Double for attributes }
  66.   mov al,[Y1]      { Get Row value }
  67.   mul dl           { Times rows }
  68.   shl ax,1
  69.   add di,ax        { ES:DI pts to upperleft corner }
  70.  
  71.   xor ch,ch
  72.   mov cl,[X2]
  73.   inc cl
  74.   sub cl,[X1]      { Number of bytes to move in CL (columns) }
  75.   xor bh,bh
  76.   mov bl,[Y2]
  77.   inc bl
  78.   sub bl,[Y1]      { Number of rows to move in BL }
  79.  
  80.   sub dl,[X2]      { Substract right site }
  81.   dec dl
  82.   shl dx,1         { Times two for attribs }
  83.   xor ah,ah        { Clear AH }
  84.   mov al,[X1]      { Left site }
  85.   shl ax,1         { Times two for attribs }
  86.   add dx,ax        { Calculated difference between last col - first col }
  87.  
  88.   mov al,[Dir]
  89.   mov ah,[Col]
  90.  
  91.   cld              { Direction flag forward }
  92.  @L1:
  93.   push cx
  94.   rep stosw
  95.   pop cx
  96.   add di,dx
  97.   dec bl
  98.   jnz @L1
  99.  
  100.   pop ds           { Restore DS and quit }
  101. end;
  102.  
  103. { Displays Veritical scrollbar }
  104. procedure ScrollBar(BarXPos,
  105.                     BarYPos : byte;
  106.                     CurPos,
  107.                     ScrLen,                     { max screen row }
  108.                     NofItems : word;
  109.                     ColAttr : byte);
  110. var barpos,maxpos : word;
  111. begin
  112.   dspat(#30,barxpos,barypos,colattr);
  113.   dspat(#31,barxpos,barypos+scrlen-1,colattr);
  114.   filltext('▒',barxpos,barypos+1,barxpos,barypos+scrlen-2,colattr);
  115.   if nofitems >= 1 then begin
  116.     maxpos := scrlen-3;
  117.     if nofitems <> 1 then barpos := round(((curpos-1)/(nofitems-1))*maxpos)
  118.     else barpos := 0;
  119.     dspat('■',barxpos,barypos+barpos+1,colattr);
  120.   end;
  121. end; { ScrollBar }
  122.  
  123. BEGIN  { demo coded by Gayle Davis for SWAG 8/18/94 }
  124.  
  125.    ClrScr;
  126.    { put at col 40 of Row x, 3rd item selected }
  127.  
  128.    FOR X := 1 to 24 DO
  129.        BEGIN
  130.        ScrollBar(40,1,x,22,40,31);
  131.        DELAY(300);
  132.        END;
  133.  
  134. END.
  135.  
  136. The assembler stuff is nicely documented, so shouldn't be a problem. What's
  137. missing here, you can define as constants at the top of your source, or try to
  138. find out using interrupt-calls or whatever...
  139.  
  140. Btw: these routines are taken from my very private video-unit, and seem to work
  141. on many different configurations (so far...) But that's also due to the fact
  142. that the v_columns is found through some interrupt-calls and stuff...
  143. The routines work also in 132x44 or whatever strange video-mode.
  144.  
  145. Another point of discussion: no snow-checking is performed. I got in some
  146. anoying discussions about this, because (imho) CGA's are hardly used these
  147. days. So it seems a little ... nuts ... to make support for that hand full of
  148. CGA-users. Ah well, enclose the sc yourself. it's not hard, but it REALY slow's
  149. stuff down. And these routines were designed with SPEED as first concern and
  150. compatibily with MODERN hardware as a second...
  151.  
  152.  _    _
  153. |_]  | _
  154. |__].|__].
  155.